﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace T4Utilities
{
    public class MethodParameters
    {
        private List<MethodParameter> _typeNames = new List<MethodParameter>();

        public void Add(string typeName, string parameterName)
        {
            _typeNames.Add(new MethodParameter(typeName, parameterName));
        }

        public void AddRange(string baseName, int amount)
        {
            for (int i = 0; i < amount; i++)
            {
                var suffix = (i + 1).ToString();
                var typeName = baseName.ToUpperInvariant() + suffix;
                var parameterName = baseName.ToLowerInvariant() + suffix;
                Add(typeName, parameterName);
            }
        }

        public string Invokation()
        {
            return string.Join(", ", _typeNames.Select(t => t.ParameterName));
        }

        public string StoreInvokation()
        {
            return string.Join(", ", _typeNames.Select(t => t.PropertyName));
        }

        public string PropertyInterface()
        {
            var storeBuilder = new StringBuilder();
            foreach (var typeName in _typeNames)
            {
                storeBuilder.AppendFormat("{0} {1} {{ get; }} ", typeName.TypeName, typeName.PropertyName);
            }

            return storeBuilder.ToString();
        }

        public string LocalStore()
        {
            var storeBuilder = new StringBuilder();
            foreach (var typeName in _typeNames)
            {
                storeBuilder.AppendFormat("public {0} {1} {{ get; private set; }} ", typeName.TypeName, typeName.PropertyName);                
            }

            return storeBuilder.ToString();
        }

        public string AssignToLocalStore()
        {
            var storeBuilder = new StringBuilder();
            foreach (var typeName in _typeNames)
            {
                storeBuilder.AppendFormat("{0} = {1}; ", typeName.PropertyName, typeName.ParameterName);
            }

            return storeBuilder.ToString();
        }

        public override string ToString()
        {            
            return string.Join(", ", _typeNames);
        }
    }
}
